package com.ruoyi.memo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.memo.domain.Countdown;
import com.ruoyi.memo.service.ICountdownService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 倒计时Controller
 * 
 * @author ruoyi
 * @date 2025-06-19
 */
@RestController
@RequestMapping("/memo/countdown")
public class CountdownController extends BaseController
{
    @Autowired
    private ICountdownService countdownService;

    /**
     * 查询倒计时列表
     */
//    @PreAuthorize("@ss.hasPermi('memo:countdown:list')")
    @GetMapping("/list")
    public TableDataInfo list(Countdown countdown)
    {
        startPage();
        List<Countdown> list = countdownService.selectCountdownList(countdown);
        return getDataTable(list);
    }

    /**
     * 导出倒计时列表
     */
    @PreAuthorize("@ss.hasPermi('memo:countdown:export')")
    @Log(title = "倒计时", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Countdown countdown)
    {
        List<Countdown> list = countdownService.selectCountdownList(countdown);
        ExcelUtil<Countdown> util = new ExcelUtil<Countdown>(Countdown.class);
        util.exportExcel(response, list, "倒计时数据");
    }

    /**
     * 获取倒计时详细信息
     */
//    @PreAuthorize("@ss.hasPermi('memo:countdown:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(countdownService.selectCountdownById(id));
    }

    /**
     * 新增倒计时
     */
//    @PreAuthorize("@ss.hasPermi('memo:countdown:add')")
    @Log(title = "倒计时", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Countdown countdown)
    {
        return toAjax(countdownService.insertCountdown(countdown));
    }

    /**
     * 修改倒计时
     */
//    @PreAuthorize("@ss.hasPermi('memo:countdown:edit')")
    @Log(title = "倒计时", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Countdown countdown)
    {
        return toAjax(countdownService.updateCountdown(countdown));
    }

    /**
     * 删除倒计时
     */
//    @PreAuthorize("@ss.hasPermi('memo:countdown:remove')")
    @Log(title = "倒计时", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(countdownService.deleteCountdownByIds(ids));
    }
}
